home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / 3DMAZE / 3_D_MAZE.C next >
Text File  |  1991-02-28  |  3KB  |  145 lines

  1. /* ===================================
  2.  
  3. File: P_D_Maze.c
  4. Function: Handle all operations for this window
  5. History: 2/15/91 Original by Prototyper.  
  6.  
  7. ================================= */
  8.  
  9. #include "P_D_Maze.h"
  10.  
  11.  
  12.     /* *********************************** */
  13.     /* These are the other includes for general routines */
  14.  
  15. #include "Strings.h"
  16.     extern char * strcpy(Str255 *, char *);
  17.  
  18.     /* *********************************** */
  19.  
  20. #define      TRUE   1
  21. #define      FALSE  0
  22. #define      NIL    0
  23.  
  24.     /* *********************************** */
  25.  
  26.  
  27.  
  28.  
  29.     WindowPtr    MyWindow;
  30.     static Rect    tempRect,temp2Rect;
  31.     static short    Index;
  32.     static ControlHandle    CtrlHandle;
  33.     static Str255    sTemp;
  34.     static OSErr    MyErr;
  35.  
  36. /* ====================================== */
  37.  
  38. /* Initialize us so all our routines can be activated */
  39. void  Init_P_D_Maze()
  40. {
  41.     MyWindow = NIL;
  42. }
  43.  
  44. /* ================================= */
  45.  
  46. /* Close our window */
  47. void  Close_P_D_Maze(whichWindow,theInput)
  48. WindowPtr  whichWindow;
  49. TEHandle *theInput;
  50. {
  51.      
  52.     if ((MyWindow != NIL) && ((MyWindow == whichWindow) || (whichWindow == (WindowPtr)-1)))
  53.     {
  54.         DisposeWindow(MyWindow); 
  55.         MyWindow = NIL; 
  56.     } 
  57.  
  58. /* ================================= */
  59.  
  60. /* ====================================== */
  61.  
  62. /* Update our window, someone uncovered a part of us */
  63. void  UpDate_P_D_Maze(whichWindow)
  64. WindowPtr  whichWindow;
  65. {
  66.     WindowPtr   SavePort;
  67.     
  68.     if ((MyWindow != NIL)  &&  (MyWindow == whichWindow))
  69.     {
  70.         GetPort(&SavePort);
  71.         SetPort(MyWindow);
  72.         DrawControls(MyWindow);
  73.         DrawMaze();
  74.         SetPort(SavePort);
  75.     }
  76. }
  77.  
  78. /* ================================= */
  79.  
  80. /* Open our window and draw everything */
  81. void Open_P_D_Maze(theInput)
  82.     TEHandle    *theInput;
  83. {
  84.     short    Index;
  85.     Rect    dataBounds;
  86.     Point    cSize;
  87.  
  88.     if (MyWindow == NIL) 
  89.     {
  90.         MyWindow = GetNewWindow(1,NIL, (WindowPtr)-1);
  91.         SetPort(MyWindow);
  92.         
  93.         ShowWindow(MyWindow);
  94.         SelectWindow(MyWindow);
  95.         InitMaze();
  96.         DrawMaze();
  97.     }
  98.     else
  99.         SelectWindow(MyWindow);
  100.         DrawMaze();    
  101. }
  102.  
  103. /* ================================= */
  104.  
  105. /* Handle action to our window, like controls */
  106. void  Do_P_D_Maze(myEvent, theInput)
  107. EventRecord    *myEvent;
  108. TEHandle    *theInput;
  109. {
  110.     short    RefCon;
  111.     short    code;
  112.     short    theValue;
  113.     WindowPtr    whichWindow;
  114.     Point    myPt;
  115.     ControlHandle    theControl;
  116.  
  117. /* Start of Window handler */
  118. if (MyWindow != NIL)
  119. {
  120.     code = FindWindow(myEvent->where, &whichWindow);
  121.     
  122.     if ((myEvent->what == mouseDown)  &&  (MyWindow == whichWindow))
  123.     {
  124.         myPt = myEvent->where;
  125.         GlobalToLocal(&myPt);
  126.          
  127.      }
  128.      
  129.     if ((MyWindow == whichWindow) &&  (code == inContent))
  130.     {
  131.         
  132.         code = FindControl(myPt, whichWindow, &theControl);
  133.         
  134.         if (code != 0) 
  135.             code = TrackControl(theControl,myPt, NIL);
  136.         
  137.     }
  138. }
  139. }
  140.  
  141. /* ================================= */
  142.  
  143.  
  144.